/**
 * NFC裂变管理 API
 */
import request from '@/libs/request'

// 获取裂变列表
export function getFissionList(data) {
  return request({
    url: '/admin/nfc/fission/index',
    method: 'get',
    params: data
  })
}

// 获取裂变详情
export function getFissionDetail(id) {
  return request({
    url: `/admin/nfc/fission/detail/${id}`,
    method: 'get'
  })
}

// 获取邀请记录
export function getFissionInvites(id, params) {
  return request({
    url: `/admin/nfc/fission/${id}/invites`,
    method: 'get',
    params
  })
}

// 禁用裂变
export function disableFission(id) {
  return request({
    url: `/admin/nfc/fission/disable/${id}`,
    method: 'post'
  })
}

// 删除裂变记录（软删除）
export function deleteFission(id) {
  return request({
    url: `/admin/nfc/fission/delete/${id}`,
    method: 'delete'
  })
}

// 获取数据分析
export function getFissionAnalytics(params = {}) {
  return request({
    url: '/admin/nfc/fission/analytics',
    method: 'get',
    params
  })
}

// 获取配置
export function getFissionConfig(params = {}) {
  return request({
    url: '/admin/nfc/fission/config',
    method: 'get',
    params
  })
}

// 保存配置
export function saveFissionConfig(data) {
  return request({
    url: '/admin/nfc/fission/config',
    method: 'post',
    data
  })
}

// 获取可用模板列表
export function getFissionTemplates() {
  return request({
    url: '/admin/nfc/fission/templates',
    method: 'get'
  })
}

// 获取商户列表
export function getFissionMerchants() {
  return request({
    url: '/admin/nfc/fission/merchants',
    method: 'get'
  })
}

// 导出裂变数据
export function exportFissionData(params) {
  return request({
    url: '/admin/nfc/fission/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 批量操作
export function batchOperateFission(action, ids) {
  return request({
    url: '/admin/nfc/fission/batch',
    method: 'post',
    data: {
      action,
      ids
    }
  })
}

export default {
  getList: getFissionList,
  getDetail: getFissionDetail,
  getInvites: getFissionInvites,
  disable: disableFission,
  delete: deleteFission,
  getAnalytics: getFissionAnalytics,
  getConfig: getFissionConfig,
  saveConfig: saveFissionConfig,
  getTemplates: getFissionTemplates,
  getMerchants: getFissionMerchants,
  export: exportFissionData,
  batchOperate: batchOperateFission
}